<?php
namespace Home\Controller;
use Think\Controller;

  
 
class UserController extends Controller {
    function __construct(){
        parent::__construct();
		
			if (!CheckLogin()) {
		
			//$this->redirect('Home/Login/index', array() , 0, '未登陆，跳转到登陆界面...');
		}       
    }

	
    public function index(){
		$UserId = getUserid(); //获取用户ID
		if($UserId){
		$A = M('tbuseraccount');
			$userInfor = $A->table('tbuseraccount a,tbuserinformation b')
							->field('a.nuserid,a.nolevel,a.nviplevel,a.nmoney,a.ngiftmoney,a.dvipendtime,b.calias,b.cidiograph')
							->where("a.nuserid=b.nuserid and a.nuserid=$UserId")
							->select();
			//是否有权限划币
			
			$flag = 0;
			if($userInfor[0]['nolevel']==7){
					$flag = 1;
				}				
			session('ifshow',$flag);
			
			$level = array('无会员','普通会员','中级会员','高级会员','高级会员','白金会员','黑钻VIP','红钻VIP','黄钻VIP','绿钻VIP','蓝钻VIP','粉钻VIP','紫钻VIP','彩钻VIP');
			$nolevel = array(
			0=>array("无特殊职务",''),
			1=>array("客服",'kefu'),
			4=>array("副站长",'fzz'),
			5=>array("站长",'zz'),
			6=>array("特权",'tequan_16'),
			7=>array("代理",'agent'),
			8=>array("艺人",'singer'),
			9=>array("至尊",'zhizun'),
			);

			
			if(!empty($userInfor[0]['dvipendtime'])){
				if(empty($userInfor[0]['nviplevel'])){
					$userInfor[0]['dvipendtime']='';
				}else{
					$userInfor[0]['dvipendtime'] = ((strtotime($userInfor[0]['dvipendtime'])-time())<=0)?'(已过期)':'';								
				}
			}
			if(!$userInfor[0]['cidiograph']){
			  $userInfor[0]['cidiograph']=1;
			}			
			$userInfor[0]['nvip'] = $level[$userInfor[0]['nviplevel']];
			$userInfor[0]['nolevelText'] = $nolevel[$userInfor[0]['nolevel']][0];
			$userInfor[0]['nolevelImg'] = $nolevel[$userInfor[0]['nolevel']][1];

			session('cidiograph', $userInfor[0]['cidiograph']);
			session('menuid', $UserId);
			session('calias', $userInfor[0]['calias']);
			
			$this->assign('userInfor',$userInfor[0]); 
			}

		$this->display();   	
    }
	

	public function Application(){
		$Model = M('tbgameinformation');
		$where['nindex2']=array('gt',0);
		
		$data = $Model->field('cname,cimage,ngameid,ntype')->where($where)->order('nindex2 asc')->select();
		foreach($data as $key=>$val){
			if($val['ntype']==1){
				$data[$key]['link']="game://".$val['ngameid'];			
			}else if($val['ntype']==2){
				$data[$key]['link']="plugin://".$val['ngameid'];
			}
		}
		$this->assign('data',$data);
		$this->display();
		
		
	
	}


	

}